/*
    This file is part of open-wars <http://code.google.com/p/open-wars/>.

    open-wars is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    open-wars is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with open-wars.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef renderer_interface_h
#define renderer_interface_h

#include <list>
#include <boost/any.hpp>

#include <common-datatypes.h>


class IRendererInterface; // Forward declaration for callback interface

typedef void(*IRendererCallback)(boost::any);
typedef struct
{
    NUMBER width;
    NUMBER height;
    NUMBER depth;
} _IRendererResResult, *IRendererResResult;

typedef void *TEXTURE;
typedef void *DISPLAYLIST;
typedef void *FONT;


// Window Callbacks
extern IRendererCallback onWindowCreated;
extern IRendererCallback onBeforeWindowClosed;
extern IRendererCallback onAfterWindowClosed;
extern IRendererCallback onWindowResized;
extern IRendererCallback onWindowMinimized;
extern IRendererCallback onWindowRestored;
extern IRendererCallback onWindowLostFocus;
extern IRendererCallback onWindowGainedFocus;
extern IRendererCallback onWindowDrawCursor;
extern IRendererCallback onWindowDraw;

// Texture Callbacks
extern IRendererCallback  onTextureLoaded;
extern IRendererCallback  onTextureLoadFailure;
extern IRendererCallback  onBeforeTextureFreed;
extern IRendererCallback  onAfterTextureFreed;

class IRendererInterface
{
    public:
        virtual ~IRendererInterface() {}

        // Window Functions
        virtual void InitializeWindow                       (NUMBER width, NUMBER height, NUMBER depth) { };
        virtual void DestroyWindow                          (void)                                      { };
        virtual void SetWindowResolution                    (NUMBER width, NUMBER height, NUMBER depth) { };
        virtual IRendererResResult GetWindowResolution      (void)                                      { return NULL; };
        virtual void SetFullScreen                          (BOOLEAN fullScreen)                        { };
        virtual void SetWindowCaption						(STRING caption)                            { };
        virtual void Repaint                                (void)                                      { };

        // Window Callbacks
        virtual void SetOnWindowCreated                     (IRendererCallback callback) { onWindowCreated      = callback; };
        virtual void SetOnBeforeWindowClosed                (IRendererCallback callback) { onBeforeWindowClosed = callback; };
        virtual void SetOnAfterWindowClosed                 (IRendererCallback callback) { onAfterWindowClosed  = callback; };
        virtual void SetOnWindowResized                     (IRendererCallback callback) { onWindowResized      = callback; };
        virtual void SetOnWindowMinimized                   (IRendererCallback callback) { onWindowMinimized    = callback; };
        virtual void SetOnWindowRestored                    (IRendererCallback callback) { onWindowRestored     = callback; };
        virtual void SetOnWindowLostFocus                   (IRendererCallback callback) { onWindowLostFocus    = callback; };
        virtual void SetOnWindowGainedFocus                 (IRendererCallback callback) { onWindowGainedFocus  = callback; };
        virtual void SetOnWindowDraw                        (IRendererCallback callback) { onWindowDraw         = callback; };

        // Texture Functions
        virtual TEXTURE LoadTextureFromFile                 (STRING fileName)            { return NULL; };
        virtual void LoadTextureFromMemory                  (void* memoryBuffer)         { };
        virtual void FreeTexture                            (TEXTURE texture)            { };
        virtual NUMBER GetTextureWidth                      (TEXTURE texture)            { return 0; };
        virtual NUMBER GetTextureHeight                     (TEXTURE texture)            { return 0; };
        virtual NUMBER GetTextureDepth                      (TEXTURE texture)            { return 0; };

        // Texture Callbacks
        virtual void SetOnTextureLoaded                     (IRendererCallback callback) { onTextureLoaded		= callback; };
        virtual void SetOnTextureLoadFailure                (IRendererCallback callback) { onTextureLoadFailure	= callback; };
        virtual void SetOnBeforeTextureFreed                (IRendererCallback callback) { onBeforeTextureFreed	= callback; };
        virtual void SetOnAfterTextureFreed                 (IRendererCallback callback) { onAfterTextureFreed	= callback; };

        // Drawing Functions
		virtual void DrawTexture							(TEXTURE texture, float x, float y, int width, int height) { };
		virtual void DrawLine								(float x1, float y1, float x2, float y2, float w, int r, int g, int b, int a) { };
		virtual void DrawRect								(float x, float y, float w, float h, int r, int g, int b, int a) {};

		// Display Functions
		virtual DISPLAYLIST DisplayCreateList				(void) 						{ return NULL; };
		virtual void DisplayBeginList						(DISPLAYLIST displayList) 	{ };
		virtual void DisplayEndList							(void)						{ };
		virtual void DisplayDrawList						(DISPLAYLIST displayList)   { };
		virtual void DisplayTranslate						(float x, float y) 			{ };
		virtual void DisplayPushMatrix						(void)						{ };
		virtual void DisplayPopMatrix						(void)						{ };
		
		// Font Functions
		virtual FONT LoadFont								(STRING fileName, int point)										{ return NULL; };
		virtual void DrawFont								(FONT font, float x, float y, int r, int g, int b, int a, STRING t)	{ };
		virtual void FreeFont								(FONT font)															{ };

        std::list<IRendererCallback> OnIdle;
};

#endif // renderer_interface_h
